'''
Created on 2014-12-25

@author: scemoon
'''
from django import  forms
from lpts.models import Product

#class OSFilterForm(forms.Form):
  #  ''' OS filter'''
   # os = forms.ModelChoiceField(Product.objects.all(), cache_choices=True)
    
def osform(request, queryset, method=None):
    ''' define  osform method
    @param queryset:  Product queryset
    @param method:  call method, inclue POST,GET. default None  '''
    
    filter_queryset = Product.objects.filter(pk__in=queryset.values_list('os'))
    class OSFilterForm(forms.Form):
        os =  forms.ModelChoiceField(filter_queryset, cache_choices=True)
    if method=="GET":
        return  OSFilterForm(request.GET)
    elif method =="POST":
        return  OSFilterForm(request.POST)
    else:
        return OSFilterForm()